# https://github.com/openai/atari-py/issues/73
def register_all_gym_envs_in_v4():
    from collections import defaultdict
    try:
        from ale_py.roms.utils import rom_name_to_id
        from ale_py.gym import GymConfig, GymFlavour, _register_gym_configs
        import ale_py.roms as roms
        legacy_games = list(map(rom_name_to_id, roms.__all__))
        obs_types = ["rgb", "ram"]
        frameskip = defaultdict(lambda: 4, [("space_invaders", 3)])

        versions = [
            GymConfig(
                "v0",
                {"repeat_action_probability": 0.25, "full_action_space": False},
                [
                    # Default for v0 has 10k steps, no idea why...
                    GymFlavour("", {"frameskip": (2, 5)}, {"max_episode_steps": 10000}),
                    # Deterministic has 100k steps, close to the standard of 108k (30 mins gameplay)
                    GymFlavour(
                        "Deterministic",
                        lambda rom: {"frameskip": frameskip[rom]},
                        {"max_episode_steps": 100000},
                    ),
                    # NoFrameSkip imposes a max episode steps of frameskip * 100k, weird...
                    GymFlavour(
                        "NoFrameskip",
                        {"frameskip": 1},
                        lambda rom: {"max_episode_steps": 100000 * frameskip[rom]},
                    ),
                ],
            ),
            GymConfig(
                "v4",
                {"repeat_action_probability": 0.0, "full_action_space": False},
                [
                    # Unlike v0, v4 has 100k max episode steps
                    GymFlavour("", {"frameskip": (2, 5)}, {"max_episode_steps": 100000}),
                    GymFlavour(
                        "Deterministic",
                        lambda rom: {"frameskip": frameskip[rom]},
                        {"max_episode_steps": 100000},
                    ),
                    # Same weird frameskip * 100k max steps for v4?
                    GymFlavour(
                        "NoFrameskip",
                        {"frameskip": 1},
                        lambda rom: {"max_episode_steps": 100000 * frameskip[rom]},
                    ),
                ],
            ),
        ]

        _register_gym_configs(legacy_games, obs_types, versions)
    except ImportError:
        pass

